/**
 * @abtract: Common js
 * @author chotrois.com
 * @version 1.0
 */
$ = jQuery.noConflict();

/**
 * Load all district of a city
 * 
 * @param city
 */
function loadDistrictPulldown($city, $target) {
    $.ajax({
	type : "POST",
	url : "/wp-admin/admin-ajax.php",
	enctype : 'multipart/form-data',
	data : {
	    'action' : "ajaxDoLoadDistrict",
	    'city' : $city
	},
	success : function(data) {
	    if (data.error != "")
		alert(data.error);
	    else
		$($target).html(data.data);
	},
	cache : false,
	dataType : "json"
    });
}

// jQuery
jQuery(document).ready(function($) {
    
    // Back to top button
    $(".scroll").click(function(event) {
	event.preventDefault();
	$('html,body').animate({
	    scrollTop : $(this.hash).offset().top
	}, 1200);
    });

    $().UItoTop({
	easingType : 'easeOutQuart'
    });

    // index.php (hover post items)
    $(".postToolTip").tooltip();

    /** implement for pulldown at search function */
    var sCity = $("#headerFrm select[name='sCity']");
    var sDistrict = $("#headerFrm select[name='sDistrict']");
    sCity.change(function() {
	loadDistrictPulldown($(this).val(), sDistrict);
    });

    // Auto load district pulldown if city != "" for district pulldown on search
    // header
    if (sCity.val() != "") {
	loadDistrictPulldown(sCity.val(), sDistrict);
	
	// Delay 0.5s because wow.js run with max time is 0.4s in attribute tag
	setTimeout(function() {
	    sDistrict.val($("#hdnSDistrict").val());
	}, 500);
    }

    /** END implement search */

    // Slide quang cao
    if ($("#flexiselDemo").length > 0) {
        $("#flexiselDemo").flexisel({
    	visibleItems : 3,
    	animationSpeed : 1000,
    	autoPlay : true,
    	autoPlaySpeed : 3000,
    	pauseOnHover : true,
    	enableResponsiveBreakpoints : true,
    	responsiveBreakpoints : {
    	    portrait : {
    	        changePoint : 480,
    	        visibleItems : 1
    	    },
    	    landscape : {
    	        changePoint : 640,
    	        visibleItems : 2
    	    },
    	    tablet : {
    	        changePoint : 768,
    	        visibleItems : 3
    	    }
    	}
        });
    }
}); // Execute immediately instead of waiting for the DOM ready event,
